package com.bba.manager.sku.service.impl;


import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.bba.manager.common.model.sku.Car;
import com.bba.manager.common.model.sku.CarVendor;
import com.bba.manager.sku.mapper.CarVendorMapper;
import com.bba.manager.sku.service.ICarVendorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 厂商汽车库存 服务实现类
 * </p>
 *
 * @author SYANDZZY
 * @since 2025-08-12
 */
@Service
public class CarVendorServiceImpl extends ServiceImpl<CarVendorMapper, CarVendor> implements ICarVendorService {

    @Override
    public CarVendor getByCarId(Long carId) {
        LambdaQueryChainWrapper<CarVendor> wrapper = new LambdaQueryChainWrapper<>(this.getBaseMapper());
        return wrapper.eq(CarVendor::getId, carId).one();
    }

    /**
     * 按条件查询
     * @param car
     * @return
     */
    @Override
    public List<CarVendor> getCarVendor(CarVendor car) {
        LambdaQueryWrapper<CarVendor> wrapper = new LambdaQueryWrapper<>();
        if (car != null) {
            // 字符串判空
            if (StringUtils.isNotBlank(car.getCarType())) {
                wrapper.eq(CarVendor::getCarType, car.getCarType());
            }
            if (StringUtils.isNotBlank(car.getColor())) {
                wrapper.eq(CarVendor::getColor, car.getColor());
            }
            // 数值判空
            if (car.getSeriesId() != null) {
                wrapper.eq(CarVendor::getSeriesId, car.getSeriesId());
            }
        }

        return this.list(wrapper);
    }
}
